#ifndef GUI_TASK_H
#define GUI_TASK_H

#include "uimgr.h"
#include "vkbd.h"
#include "cnckernel.h"

/**
GUI background task.
This class manages the GUI module.
*/
class GUITask : public cnc::base::CooperativeTask
{
	cnc::ui::Services *srv_;
	cnc::ui::VKServices *vksrv_;
	MSG msg;
public:
	GUITask()
	{
		cnc::ui::Manager *mgr = cnc::ui::getManager();
		srv_ = mgr->getServices();
		cnc::ui::VirtualKeyboard *vk = cnc::ui::getVirtualKeyboard();
		vksrv_ = vk->getVKServices();
	}
	virtual void start()
	{
		srv_->start();
		vksrv_->start();
		vksrv_->setState(cnc::comm::CYCLE::ID, cnc::comm::CYCLE::FEED_HOLD);
		vksrv_->setState(cnc::comm::MODE::ID, cnc::comm::MODE::HOME);
		vksrv_->setState(cnc::comm::OPTION::ID, cnc::comm::OPTION::SINGLE_BLOCK_OFF);
		vksrv_->setState(cnc::comm::FEEDRATE_OVERRIDE::ID, 100);
		vksrv_->setState(cnc::comm::JOG_FEEDRATE::ID, 1000);
		vksrv_->setState(cnc::comm::RAPID_FEEDRATE_OVERRIDE::ID, 100);
		vksrv_->setState(cnc::comm::SPINDLE::ID, cnc::comm::SPINDLE::NORMAL_ROTATION);
		vksrv_->setState(cnc::comm::SPINDLE::ID, cnc::comm::SPINDLE::STOP);
		vksrv_->setState(cnc::comm::SPINDLE_SPEED::ID, 100);
		vksrv_->setState(cnc::comm::SPINDLE_OVERRIDE::ID, 100);
		vksrv_->setState(cnc::comm::HANDWHEEL::ID, cnc::comm::HANDWHEEL::FACTOR_1);
		vksrv_->setState(cnc::comm::HANDWHEEL::ID, cnc::comm::HANDWHEEL::SELECT_AXIS_X);
		vksrv_->setState(cnc::comm::TOOL::ID, 2);
	}
	virtual bool execute()
	{
		return srv_->execute() && vksrv_->execute();
	}
	virtual void stop()
	{
		srv_->stop();
		vksrv_->stop();
	}
};

#endif
